package com.da.javatest.leetCode2;

public class Code747 {
    public static void main(String[] args) {
        System.out.println(new Code747().dominantIndex(new int[]{0, 0, 0, 1}));
    }

    public int dominantIndex(int[] nums) {
        if (nums.length == 1) {
            return 0;
        }
        int max1, max2, index;
        if (nums[0] > nums[1]) {
            index = 0;
            max1 = nums[0];
            max2 = nums[1];
        } else {
            index = 1;
            max1 = nums[1];
            max2 = nums[0];
        }
        for (int i = 2; i < nums.length; i++) {
            if (nums[i] > max1) {
                max2 = max1;
                max1 = nums[i];
                index = i;
                continue;
            }
            if (nums[i] > max2) {
                max2 = nums[i];
            }
        }
        if (max1 >= max2 * 2) {
            return index;
        }
        return -1;
    }
}
